<?php
    if($this->controller == 'index' || $this->controller == '') $class = 'inicial';
    else if($this->controller == 'ambientes' && ($this->action == 'index' || $this->action == '')) $class = 'pagbot';
    else $class = 'pagina';
?>
<?php

function setmenu($op,$cont){
    $class = '';
    if($op == $cont) $class = 'class="action"';
    echo $class;
}

$id = 0;
if($this->controller == 'ambientes'){
    $front = Zend_Controller_Front::getInstance();
    $id = $front->getRequest()->getParam('id', 0);
}

function sub_menu_amb($urlbase,$id){
    
    $db = Zend_Db_Table_Abstract::getDefaultAdapter();
    
    $html = '';

    $html .= '<div class="c_a_men_amb">';
        $html .= '<div class="slider-prj">';

            $query = 'SELECT SQL_CACHE * FROM AMBIENTES WHERE AMB_STA = 1 ORDER BY AMB_ORD ASC';
            $result = $db->fetchAll($query);
            
            $html .= '<ul>';
            foreach($result as $row) { 
                $style = $row['AMB_ID'] == $id ? 'style="display:block !important;"':'';
                $img = glob('public/upload/ambientes/'.$row['AMB_ID'].'_crs.*');
                if(isset($img[0])) { 
                    $html .= '<li id="'.$row['AMB_ID'].'">';
                        $html .= '<a href="'.$urlbase.'/ambientes/detalhe/id/'.$row['AMB_ID'].'">';
                            $html .= '<img src="'.$urlbase.'/'.$img[0].'"  />';
                            $html .= '<div class="img-dsc" '.$style.'>';
                                $html .= '<div class="i_d_txt">'.$row['AMB_NOM'].'</div>';
                            $html .= '</div>';
                        $html .= '</a>';
                    $html .= '</li>';
                } 
            }  
            $html .= '</ul>'; 
        $html .= '</div>';
    $html .= '</div>';
    
    echo $html;
}

?>
<header>
    <div id="st-tp-content">
        <nav id="st-tp-menu" class="<?php echo $class; ?>">
            <ul class="menu">
                <li><a href="<?php echo $this->urlbase.'/'; ?>" class="logo"></a></li>
            <?php foreach($this->paginasite as $pag) { 
                if(strlen($pag['PGS_LNK']) > 1 && $pag['PGS_LNK'] != 'ambientes') $url = $this->urlbase.'/'.$pag['PGS_LNK'];
                else $url = 'javascript:void(0)';
            ?>
                <li class="m_<?php echo $pag['PGS_LNK']; ?>">
                    <a <?php setmenu($pag['PGS_LNK'], $this->controller); ?> href="<?php echo $url; ?>"><?php echo $pag['PGS_NOM']; ?></a>
                    <?php if($pag['PGS_LNK'] == 'ambientes') echo sub_menu_amb($this->urlbase,$id); ?>
                </li>
            <?php } ?>
            </ul>
        </nav>    
    </div>
</header>

<?php // auto: 4, scroll: 1, wrap: 'circular'  ?>
<script src="<?php echo $this->urlbase;?>/public/media/js/jquery.jcarousel.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {  
    $('.slider-prj').jcarousel({ scroll: 1  }); 
});
</script> 